import { useEffect, useState } from "react"
import { useHistory } from "react-router-dom";


function NotFound() {
    const history = useHistory()
    const [time, setTime] = useState(3)
    useEffect(() => {
        let timer = setTimeout(() => {
            setTime(time => time - 1)
        }, 1000);
        if (time === 0) {
            clearTimeout(timer)
            history.push('/home')
        }
    }, [time, history])
    return (
        <div>
            <h1>对不起,您访问的页面不存在</h1>
            <div> {time}秒后自动 <a href="/home">跳转到首页</a></div>
        </div>
    )
}

export default NotFound